package com.caishi.lkx.user.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.caishi.lkx.user.dto.SelectCategoryDto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zzw.common.service.model.NameModel;
import com.zzw.common.mysql.handler.DataEncryptionHandler;
import com.caishi.lkx.user.ienum.type.UserChannelType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("cu_member")
public class MemberModel extends IUserModel<MemberModel> implements NameModel<MemberModel, String> {
    /**
     * 邮箱
     */
    @TableField(typeHandler = DataEncryptionHandler.class)
    private String email;

    /**
     * 学号
     */
    @TableField(typeHandler = DataEncryptionHandler.class)
    private String stuNo;

    /**
     * 机构专业id
     */
    private Long groupId;
    /**
     * 组织id
     */
    private Long departmentId;

    /**
     * 用户渠道类型
     */
    private UserChannelType channelType;

    /**
     * 用户渠道指向
     */
    private String channelPointer;

    private LocalDate birthday;
    /**
     * 身份证
     */
    private String card;
    /**
     * 描述
     */
    private String description;
    //机构用户过期时间
    private LocalDateTime expireTime;

    private Long categoryId;

    private String account;
    private LocalDateTime kaoyanExpireTime;

    @TableField(exist = false)
    @Schema(title = "0:已过期 1:未过期")
    private Boolean status;
    //智图userKey
    private String userKey;
    @TableField(exist = false)
    @Schema(title = "是否同步到vers")
    private Boolean isSyncVers;

    @TableField(typeHandler = FastjsonTypeHandler.class, value = "select_category")
    @JsonIgnore
    private List<SelectCategoryDto> selectCategory;



    @Override
    public MemberModel InstanceThisObj() {
        return new MemberModel();
    }

    public MemberModel clearSensitiveData() {
        super.clearSensitiveData();
        this.setStuNo(null);
        return this;
    }
    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
        if(null != expireTime){
            this.status= !(expireTime.isBefore(LocalDateTime.now()));
        }
    }

    @Deprecated
    public void setStatus(Boolean status) {
        this.status = status;
    }
}
